<template>
  <div class="carousel-container">
    <el-carousel 
      :interval="5000" 
      :arrow="arrow" 
      indicator-position="outside"
      height="400px"
      class="hero-carousel"
    >
      <el-carousel-item 
        v-for="(item, index) in props.allSlideshow" 
        :key="index"
        class="carousel-item"
        @click="goToArticle(item)"
      >
        <div class="carousel-content">
          <!-- 背景图片 -->
          <div class="carousel-bg">
            <el-image 
              :src="item.postlink" 
              fit="cover"
              class="bg-image"
            >
              <template #error>
                <div class="image-slot">
                  <el-icon><Picture /></el-icon>
                </div>
              </template>
            </el-image>
            <div class="overlay"></div>
          </div>
          
          <!-- 内容区域 -->
          <div class="content-wrapper">
            <div class="content-inner">
              <!-- 分类标签 -->
              <div class="category-tag">
                <el-tag type="danger" size="large" round>
                  <el-icon><Star /></el-icon>
                  热门推荐
                </el-tag>
              </div>
              
              <!-- 标题 -->
              <h2 class="carousel-title">{{ item.title }}</h2>
              
              <!-- 描述 -->
              <p class="carousel-description">{{ item.introduction }}</p>
              
              <!-- 元信息 -->
              <div class="carousel-meta">
                <div class="author-info">
                  <el-avatar 
                    :src="item.userInfo.avatar" 
                    :size="32"
                    class="author-avatar"
                  >
                    <el-icon><User /></el-icon>
                  </el-avatar>
                  <span class="author-name">{{ item.userInfo.user.name }}</span>
                </div>
                
                <div class="meta-info">
                  <span class="date">
                    <el-icon><Calendar /></el-icon>
                    {{ formatDate(item.createdAt) }}
                  </span>
                  <span class="views">
                    <el-icon><View /></el-icon>
                    {{ item.readnumber || 0 }}
                  </span>
                </div>
              </div>
              
              <!-- 阅读按钮 -->
              <div class="action-button">
                <el-button 
                  type="primary" 
                  size="large" 
                  round

                  @click.stop="goToArticle(item.id)"
                >
                  <el-icon><Reading /></el-icon>
                  立即阅读
                </el-button>
              </div>
            </div>
          </div>
        </div>
      </el-carousel-item>
    </el-carousel>
  </div>
</template>

<script setup>
import { ref, computed } from 'vue'
import { useRouter } from 'vue-router'
import { 
  ElCarousel, 
  ElCarouselItem, 
  ElImage, 
  ElTag, 
  ElIcon, 
  ElAvatar, 
  ElButton 
} from 'element-plus'
import { 
  Picture, 
  Star, 
  User, 
  Calendar, 
  View, 
  Reading 
} from '@element-plus/icons-vue'

const router = useRouter()
const props = defineProps({
  allSlideshow: {
    type: Array,
    default: () => []
  },
  lunfanData: {
    type: Array,
    default: () => []
  }
})

// 响应式箭头显示
const arrow = computed(() => {
  return window.innerWidth > 768 ? 'hover' : 'never'
})

const goToArticle = (num) => {
  router.push({ path: '/articleDetails', query: { id: num } })
}

const formatDate = (dateString) => {
  if (!dateString) return ''
  const date = new Date(dateString)
  return date.toLocaleDateString('zh-CN', {
    year: 'numeric',
    month: '2-digit',
    day: '2-digit'
  })
}
</script>

<style scoped lang="less">
.carousel-container {
  width: 100%;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
  
  .hero-carousel {
    border-radius: 20px;
    overflow: hidden;
    
    :deep(.el-carousel__container) {
      border-radius: 20px;
    }
    
    :deep(.el-carousel__indicators) {
      bottom: 20px;
      
      .el-carousel__indicator {
        .el-carousel__button {
          width: 12px;
          height: 12px;
          border-radius: 50%;
          background: rgba(255, 255, 255, 0.5);
          border: 2px solid rgba(255, 255, 255, 0.3);
          transition: all 0.3s ease;
        }
        
        &.is-active .el-carousel__button {
          background: #409eff;
          border-color: #409eff;
          transform: scale(1.2);
        }
      }
    }
    
    :deep(.el-carousel__arrow) {
      background: rgba(255, 255, 255, 0.9);
      color: #409eff;
      border: none;
      width: 48px;
      height: 48px;
      border-radius: 50%;
      transition: all 0.3s ease;
      
      &:hover {
        background: #409eff;
        color: white;
        transform: scale(1.1);
      }
    }
  }
}

.carousel-item {
  cursor: pointer;
  border-radius: 20px;
  overflow: hidden;
}

.carousel-content {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  border-radius: 20px;
  overflow: hidden;
}

.carousel-bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  
  .bg-image {
    width: 100%;
    height: 100%;
    transition: transform 0.5s ease;
  }
  
  .image-slot {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-size: 48px;
  }
  
  .overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(
      135deg,
      rgba(0, 0, 0, 0.4) 0%,
      rgba(0, 0, 0, 0.2) 50%,
      rgba(0, 0, 0, 0.6) 100%
    );
    z-index: 2;
  }
}

.content-wrapper {
  position: relative;
  z-index: 3;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  padding: 0 60px;
}

.content-inner {
  max-width: 600px;
  color: white;
  animation: slideInUp 0.8s ease-out;
}

.category-tag {
  margin-bottom: 20px;
  
  .el-tag {
    font-size: 14px;
    padding: 8px 16px;
    background: rgba(245, 108, 108, 0.9);
    border: none;
    color: white;
    backdrop-filter: blur(10px);
    
    .el-icon {
      margin-right: 6px;
    }
  }
}

.carousel-title {
  font-size: 2.5rem;
  font-weight: 700;
  line-height: 1.2;
  margin: 0 0 16px 0;
  text-shadow: 2px 2px 8px rgba(0, 0, 0, 0.3);
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

.carousel-description {
  font-size: 1.1rem;
  line-height: 1.6;
  margin: 0 0 24px 0;
  opacity: 0.95;
  text-shadow: 1px 1px 4px rgba(0, 0, 0, 0.3);
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
}

.carousel-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 32px;
  flex-wrap: wrap;
  gap: 16px;
}

.author-info {
  display: flex;
  align-items: center;
  gap: 12px;
  
  .author-avatar {
    border: 2px solid rgba(255, 255, 255, 0.8);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  }
  
  .author-name {
    font-size: 16px;
    font-weight: 600;
    text-shadow: 1px 1px 4px rgba(0, 0, 0, 0.3);
  }
}

.meta-info {
  display: flex;
  gap: 20px;
  
  .date,
  .views {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    opacity: 0.9;
    
    .el-icon {
      font-size: 16px;
    }
  }
}

.action-button {
  .el-button {
    padding: 12px 32px;
    font-size: 16px;
    font-weight: 600;
    background: linear-gradient(135deg, #409eff 0%, #79bbff 100%);
    border: none;
    box-shadow: 0 8px 20px rgba(64, 158, 255, 0.3);
    transition: all 0.3s ease;
    
    &:hover {
      transform: translateY(-2px);
      box-shadow: 0 12px 30px rgba(64, 158, 255, 0.4);
    }
    
    .el-icon {
      margin-right: 8px;
    }
  }
}

// 悬停效果
.carousel-item:hover {
  .bg-image {
    transform: scale(1.05);
  }
  
  .carousel-title {
    color: #ffd700;
  }
}

// 动画
@keyframes slideInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

// 响应式设计
@media screen and (max-width: 1024px) {
  .content-wrapper {
    padding: 0 40px;
  }
  
  .carousel-title {
    font-size: 2rem;
  }
  
  .carousel-description {
    font-size: 1rem;
  }
}

@media screen and (max-width: 768px) {
  .carousel-container {
    border-radius: 16px;
    
    .hero-carousel {
      height: 320px !important;
      border-radius: 16px;
      
      :deep(.el-carousel__container) {
        border-radius: 16px;
      }
      
      :deep(.el-carousel__arrow) {
        display: none;
      }
    }
  }
  
  .content-wrapper {
    padding: 0 24px;
  }
  
  .content-inner {
    max-width: 100%;
    text-align: center;
  }
  
  .carousel-title {
    font-size: 1.5rem;
    margin-bottom: 12px;
  }
  
  .carousel-description {
    font-size: 0.9rem;
    margin-bottom: 20px;
    -webkit-line-clamp: 2;
  }
  
  .carousel-meta {
    flex-direction: column;
    gap: 12px;
    margin-bottom: 24px;
  }
  
  .meta-info {
    gap: 16px;
  }
  
  .action-button {
    .el-button {
      padding: 10px 24px;
      font-size: 14px;
    }
  }
}

@media screen and (max-width: 480px) {
  .carousel-container {
    .hero-carousel {
      height: 280px !important;
    }
  }
  
  .content-wrapper {
    padding: 0 16px;
  }
  
  .carousel-title {
    font-size: 1.3rem;
  }
  
  .carousel-description {
    font-size: 0.85rem;
  }
  
  .author-info {
    .author-name {
      font-size: 14px;
    }
  }
  
  .meta-info {
    .date,
    .views {
      font-size: 12px;
    }
  }
}
</style>
